// pages/classifyDetail/classifyDetail.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    img1: "../../images/47.png",
    img2: "../../images/47a.png",
    img3: "../../images/47b.png",
    shopimg: "../../images/shopimg.png",
    thumbUrl: getApp().globalData.thumbUrl,
    type: 1,
    mold1: 1,
    mold2: 3,
    shopList: [],
    pid: 0,
    page: 1

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var id = options.id;
    var param = {
      type: 1,
      id: id
    };
    app.wxRequest('POST', "Index/getRobGoodsList", param, (res) => {
      var data = res.data;
      that.setData({
        shopList: data,
        pid: id
      })
      console.log(res)
    }, (err) => {
      console.log(err.errMsg)
    })
  },
  showTab: function (e) {
    var that = this;
    var mold = e.currentTarget.dataset.mold;
    var type = that.data.type;
    var mold1 = that.data.mold1;
    var mold2 = that.data.mold2;
    if (mold == 1) {
      if (mold1 == 1 || mold1 == 3) {
        var type = 2;
        that.setData({
          type: 2,
          mold1: 2,
          mold2: 3,
          page: 1
        })
      } else if (mold1 == 2) {
        var type = 1;
        that.setData({
          type: 1,
          mold1: 1,
          mold2: 3,
          page: 1
        })
      }
    } else {
      if (mold2 == 1 || mold2 == 3) {
        var type = 3;
        that.setData({
          type: 3,
          mold1: 3,
          mold2: 2,
          page: 1
        })
      } else if (mold2 == 2) {
        var type = 4;
        that.setData({
          type: 4,
          mold1: 3,
          mold2: 1,
          page: 1
        })
      }
    }
    var pid = that.data.pid;
    var param = {
      type: type,
      page: 1,
      id: pid
    };
    app.wxRequest('POST', "Index/getRobGoodsList", param, (res) => {
      var data = res.data;
      that.setData({
        shopList: data
      })
    }, (err) => {
      console.log(err.errMsg)
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.showNavigationBarLoading();
    var that = this;
    var type = that.data.type;
    var id = that.data.pid;
    var param = {
      type: type,
      id: id,
      page: 1
    };
    app.wxRequest('POST', "Index/getRobGoodsList", param, (res) => {
      var data = res.data;
      that.setData({
        shopList: data
      })
    }, (err) => {
      console.log(err.errMsg)
    })
    setTimeout(function () {
      wx.hideNavigationBarLoading();
      wx.stopPullDownRefresh();
    }, 1500)

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    var id = that.data.pid;
    var page = that.data.page;
    var type = that.data.type;
    var page = parseInt(page) + 1;
    var shopList = that.data.shopList;
    var param = {
      id: id,
      page: page,
      type: type
    };
    app.wxRequest('POST', "Index/getRobGoodsList", param, (res) => {
      var data = res.data;
      var code = res.code;
      if (code == 1) {
        that.setData({
          shopList: shopList.concat(data),
          page: page
        })
      } else {
        wx.showToast({
          title: '我是有底线的...',
          icon: "none",
          duration: 1500
        })
      }

    }, (err) => {
      console.log(err.errMsg)
    })
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // },
  toshopDetail(e) {
    var that = this;
    var id = e.currentTarget.dataset.id;
    var name = e.currentTarget.dataset.name;
    var uid = wx.getStorageSync('uid')
    if (uid) {
      wx.navigateTo({
        url: '/pages/robGoodsDetails/robGoodsDetails?id=' + id + "&name=" + name,
      })
    } else {
      wx.navigateTo({
        url: '../authorization/authorization',
      })
    }

  }
})